<?php
namespace Mobile\Model;

use Think\Model;

/**
 * 用户模型
 */
class tmpmsgModel extends Model
{

    protected $tableName = 'tmpmsg';

    
    /*
     * 统计数量
     */
    public function gettmpmsgCount($where)
    {
        $res = $this->where($where)->count();
        return $res;
    }
    
    /*
     * 添加
     */
    public function addtmpmsg($data)
    {
        $id = $this->add($data);
		
		$url = "/mobile/backopen?id=".$id;
        $this->_backOpen($url);
		
        return $res;
    }
    
    /*
     * 获取信息
     */
    public function gettmpmsg($where)
    {
        $res = $this->where($where)->order("send_plan_time ASC,send_priority DESC")->limit(100)->select();
        return $res;
    }
    
    /*
     * 获取信息
     */
    public function getDetail($where)
    {
        $res = $this->where($where)->find();
        return $res;
    }
    
    /*
     * 编辑信息
     */
    public function edittmpmsg($where, $data)
    {
        return $this->where($where)->save($data);
    }
	
	
    /*
     * 异步执行
     */
    public function _backOpen($url){
        
        $domain = $_SERVER['HTTP_HOST'];
        $fp = fsockopen($domain, 80, $errno, $errstr, 10);
        if (!$fp) {
            return false;
            //echo "$errstr ($errno)<br />\n";
        } else {
            $out = "GET ".$url."  / HTTP/1.1\r\n";
            $out .= "Host: ".$domain."\r\n";
            $out .= "Connection: Close\r\n\r\n";
            fwrite($fp, $out);
            /*忽略执行结果
             while (!feof($fp)) {
             echo fgets($fp, 128);
            }*/
            fclose($fp);
        }
    }
	
	
}
